package cn.itcast.itcaststore.web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

//@WebFilter("/ListProductServlet")
public class ListProductFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {

        String currentPage = request.getParameter("currentPage");
        String category = request.getParameter("category");
        String orderByDate="2";
        if (currentPage==null){
            currentPage="1";
        }
        if (category==null){
            category="";
        }

        System.out.println(currentPage);
        System.out.println(orderByDate);
        request.setAttribute("currentPage",Integer.parseInt(currentPage ));
        request.setAttribute("orderByDate",Integer.parseInt(orderByDate ));
        request.setAttribute("category", category);

        chain.doFilter(request, response);
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
